package com.lottery.im.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.lottery.im.R;
import com.lottery.im.util.ScreenUtils;

public class BottomSelectDialog {

  private static Dialog mDialog;

  public Dialog create(Context context, String des, String select1, String select2,
      View.OnClickListener listener1, View.OnClickListener listener2) {
    mDialog = new Dialog(context, R.style.BottomSelectDialogTheme);
    Window window = mDialog.getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    mDialog.setContentView(R.layout.dialog_bottom_select);
    window.setGravity(Gravity.BOTTOM);
    window.setWindowAnimations(R.style.bottom_animation);
    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ScreenUtils.getWidth(context);
    window.setAttributes(params);
    TextView mTvDes = mDialog.findViewById(R.id.tv_dialog_des);
    TextView mTvSelect1 = mDialog.findViewById(R.id.tv_dialog_select1);
    TextView mTvSelect2 = mDialog.findViewById(R.id.tv_dialog_select2);
    mTvDes.setText(des);
    mTvSelect1.setText(select1);
    mTvSelect2.setText(select2);
    mTvSelect1.setOnClickListener(listener1);
    mTvSelect2.setOnClickListener(listener2);
    mDialog.findViewById(R.id.tv_dialog_cancel).setOnClickListener(v -> mDialog.dismiss());
    return mDialog;
  }

  public static void dismiss() {
    if (mDialog != null) {
      mDialog.dismiss();
    }
    mDialog = null;
  }

  public Dialog create(Context context, String select1,
      View.OnClickListener listener1) {
    mDialog = new Dialog(context, R.style.BottomSelectDialogTheme);
    Window window = mDialog.getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    mDialog.setContentView(R.layout.dialog_bottom_select);
    window.setGravity(Gravity.BOTTOM);
    window.setWindowAnimations(R.style.bottom_animation);
    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ScreenUtils.getWidth(context);
    window.setAttributes(params);
    TextView mTvDes = mDialog.findViewById(R.id.tv_dialog_des);
    TextView mTvSelect1 = mDialog.findViewById(R.id.tv_dialog_select1);
    TextView mTvSelect2 = mDialog.findViewById(R.id.tv_dialog_select2);
    mTvDes.setVisibility(View.GONE);
    mTvSelect1.setText(select1);
    mTvSelect2.setVisibility(View.GONE);
    mTvSelect1.setOnClickListener(listener1);
    mDialog.findViewById(R.id.tv_dialog_cancel).setOnClickListener(v -> mDialog.dismiss());
    return mDialog;
  }
}
